#include<iostream>
#include<vector>
#include<set>
using namespace std;

void _Permutation(string str, int begin, set<string>& result) {
    if (begin == str.size() - 1) {
        result.insert(str);
        return;
    }

    for (int i = begin; i < str.size(); i++) {
        swap(str[begin], str[i]);
        _Permutation(str, begin + 1, result);
        swap(str[begin], str[i]);
    }
}

vector<string> Permutation(string str) {
    set<string> result;
    _Permutation(str, 0, result);

    vector<string>ret(result.begin(), result.end());
    return ret;
}

int main()
{
    string s = "abc";
    vector<string> ret = Permutation(s);
    for (auto str : ret)
    {
        cout << str << " ";
    }
    cout << endl;
    return 0;
}